/*
 * Created by JFormDesigner on Thu Nov 12 17:12:47 CET 2009
 */

package at.jku.pervasive.gui.jformdesigner;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

import at.jku.pervasive.Measurement;
import at.jku.pervasive.Position;
import at.jku.pervasive.gui.action.RecordAction;

import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;

/**
 * @author SHOCKIE
 */
public class RecordingPanel extends JPanel
{
	public RecordingPanel()
	{
		initComponents();

		measurementInfoLabel.setText("");
	}

	public void setTagAssigmentPanel(TagAssignmentPanel tagAssignmentPanel)
	{
		recordButton.setAction(new RecordAction(this, tagAssignmentPanel));
	}

	private void initComponents()
	{
		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Open Source Project license - unknown
		JScrollPane descriptionScrollPane = new JScrollPane();
		descriptionTextArea = new JTextArea();
		JPanel southPanel = new JPanel();
		measurementInfoLabel = new JLabel();
		recordButton = new JButton();
		JSeparator separator = new JSeparator();
		allTagActivitiesPanel = new TagActivityPanel();
		CellConstraints cc = new CellConstraints();

		// ======== this ========
		setBorder(new TitledBorder(" Measurement recording "));
		setLayout(new FormLayout(ColumnSpec.decodeSpecs("default:grow"), new RowSpec[] {
				new RowSpec("max(default;50dlu)"), FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
				FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC,
				new RowSpec(RowSpec.CENTER, Sizes.DEFAULT, FormSpec.DEFAULT_GROW) }));

		// ======== descriptionScrollPane ========
		{
			descriptionScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

			// ---- descriptionTextArea ----
			descriptionTextArea.setTabSize(2);
			descriptionScrollPane.setViewportView(descriptionTextArea);
		}
		add(descriptionScrollPane, cc.xywh(1, 1, 1, 1, CellConstraints.FILL, CellConstraints.FILL));

		// ======== southPanel ========
		{
			southPanel.setLayout(new FormLayout(new ColumnSpec[] {
					new ColumnSpec(ColumnSpec.LEFT, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
					FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC }, RowSpec
					.decodeSpecs("default:grow")));

			// ---- measurementInfoLabel ----
			measurementInfoLabel.setText("text");
			southPanel.add(measurementInfoLabel, cc.xy(1, 1));

			// ---- recordButton ----
			recordButton.setText("text");
			southPanel.add(recordButton, cc.xywh(3, 1, 1, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT));
		}
		add(southPanel, cc.xy(1, 3));
		add(separator, cc.xy(1, 5));
		add(allTagActivitiesPanel, cc.xy(1, 7));
		// //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	// Generated using JFormDesigner Open Source Project license - unknown
	private JTextArea descriptionTextArea;
	private JLabel measurementInfoLabel;
	private JButton recordButton;
	private TagActivityPanel allTagActivitiesPanel;

	// JFormDesigner - End of variables declaration //GEN-END:variables

	public void clearAllTagPositions()
	{
		this.allTagActivitiesPanel.clearAllTagPositions();
	}

	public void addTagPosition(Position newPosition)
	{
		this.allTagActivitiesPanel.addTagPosition(newPosition);
	}

	public void setInfoText(String text)
	{
		measurementInfoLabel.setText(text);
	}

	public String getDescription()
	{
		return descriptionTextArea.getText();
	}

	public void setLoadedMeasurement(Measurement measurement)
	{
		// set description
		descriptionTextArea.setText(measurement.getDescription());

		this.allTagActivitiesPanel.setTagPositions(measurement.getPositions());
	}

}
